﻿<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
    style="padding: 20px 30px 0 0;">

    <script type='text/html' template lay-done='layui.data.init(d);'>
        <input type='hidden' name='PID' value="{{ d.params.PID || '' }}" />
        <input type='hidden' name='UserType_Sel' value="0" />
    </script>
    <div class='layui-form-item'>
        <label class='layui-form-label'>用户名 <label style="color: red">*</label></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='UserID' id='UserID' value='{{ d.params.UserID || '' }}' lay-verify='required' placeholder='用户名' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>真实姓名 <label style="color: red">*</label></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='UserName' value='{{ d.params.UserName || '' }}' lay-verify='required' placeholder='真实姓名' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <!-- <div class='layui-form-item'>
        <label class='layui-form-label'>用户头像</label>
        <div class='layui-input-inline'>
            <script type='text/html' template lay-done='layui.data.setUpload(d);'>
                <input type='text' name='Photo_Upload' id='Photo_Upload' value='{{ d.params.Photo_Upload || '' }}' placeholder='请上传图片' autocomplete='off' class='layui-input'>
            </script>
        </div>
        <div class='layui-input-inline layui-btn-container' style='width: auto;'>
            <button type='button' class='layui-btn layui-btn-primary' id='Photo_UploadBtn'>
                <i class='layui-icon'>&#xe67c;</i>上传图片
            </button>
            <button class='layui-btn layui-btn-primary' layadmin-event='Photo_UploadImg'>查看图片</button>
        </div>
    </div> -->
    <div class='layui-form-item'>
        <label class='layui-form-label'>手机号 <label style="color: red">*</label></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Mobile' value='{{ d.params.Mobile || '' }}' lay-verify='required' placeholder='手机号' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <!--<div class='layui-form-item'>
        <label class='layui-form-label'>用户类型 </label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                    <select name='UserType_Sel' lay-filter="seltype">
                        <option value='0' {{ d.params.UserType_Sel == '0' ? 'selected' : '' }}>系统管理员</option>
                        <option value='1' {{ d.params.UserType_Sel == '1' ? 'selected' : '' }}>网点</option>
                        <option value='2' {{ d.params.UserType_Sel == '2' ? 'selected' : '' }}>供应商</option>
                    </select>
                </script>
        </div>
    </div>-->

    <!--<div class='layui-form-item'>
        <label class='layui-form-label'>最后登录时间</label>
        <div class='layui-input-inline'>
            <script type='text/html' template lay-done='layui.data.datedone(d.params);'>
                <input type='text' name='LastLoginTime' readonly='readonly' id='LastLoginTime' value='{{ d.params.LastLoginTime || '' }}' lay-verify='datetime' placeholder='yyyy-MM-dd HH:mm:ss' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>-->


    <!--<div class='layui-form-item' id="Groupdiv" style="display:none">
        <label class='layui-form-label'>所属组织</label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <select name="groupId" xm-select="groupId" xm-select-radio="" xm-select-search="" xm-select-skin="default">
                    <option value=""></option>
                </select>
            </script>
        </div>
    </div>-->


  <!--<div class='layui-form-item' id="Departdiv">
        <label class='layui-form-label'> 所属部门</label>
        <div class='layui-input-block'>
            <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"DepartmentID_SelSource");'>
                <select name='DepartmentID_SelSource' readonly='readonly' id='DepartmentID_SelSource' lay-search></select>
            </script>
        </div>
    </div>-->

    <div class='layui-form-item'>
        <label class='layui-form-label'>邮箱</label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Email' value='{{ d.params.Email || '' }}' placeholder='邮箱' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>状态</label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <select name='State_Sel'>
                    <option value='0' {{ d.params.State_Sel == '0' ? 'selected' : '' }}>启用</option>
                    <option value='1' {{ d.params.State_Sel == '1' ? 'selected' : '' }}>停用</option>
                </select>
            </script>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>备注</label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Remark' value='{{ d.params.Remark || '' }}' placeholder='备注' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" value="确认" class="layui-btn">
        </div>
    </div>
</div>

<script type="text/javascript">



    layui.data.init = function (d, sourceName) {
        layui.use(['form', 'admin', 'tree', 'formSelects'], function () {
            var $ = layui.$;
            var form = layui.form;
            var admin = layui.admin;
            var tree = layui.tree;
            var formSelects = layui.formSelects;

            //debugger
            if (d.params.PID) {
                $("#UserID").attr("readonly", "readonly");
            }

            //var isGroupYun = false; 

            ////获取用户的组织
            //admin.req({
            //    url: layui.setter.APIUrl + '/WebAPI/user/userInfo', //实际使用s改成服务端真实接口
            //    type: 'post',
            //    done: function (res) {
            //        //判断是否为云端组织
            //        if (res.Data.GroupID == "6E0647FD-105B-41F6-929A-32BC9D1CF5F1") {
            //            isGroupYun = true;
            //            $("#Groupdiv").attr("style", "display:block;");//显示
            //            //$("#Departdiv").attr("style", "display:block;");
            //        } else {
            //            $("#Groupdiv").attr("style", "display:none;");//不显示
            //            //$("#Departdiv").attr("style", "display:none;");
            //        }
            //    }
            //});


            //formSelects.config('groupId', {
            //    keyName: 'title',            //自定义返回数据中name的key, 默认 name
            //    keyVal: 'id',            //自定义返回数据中value的key, 默认 value
            //    keyChildren: 'children',    //联动多选自定义children
            //});

            //admin.req({
            //    url: layui.setter.APIUrl + '/admin/groupMgr/getParentGroupdataSelect', //实际使用请改成服务端真实接口
            //    type: 'post',
            //    done: function (res) {
            //        formSelects.data('groupId', 'local', {
            //            arr: res.Data
            //        });
            //        layui.formSelects.value('groupId', [d.params.GroupID]);
            //    }
            //});



            //formSelects.on('groupId', function (id, vals, val, isAdd, isDisabled) {
            //    if (val.id == "-1") {
            //        layer.msg("不能选择全部");
            //        return false;
            //    }

            //    if (!val.id) {
            //        $('#DepartmentID_SelSource').empty();
            //        form.render('select');
            //    } else {
            //        //改变部门数据
            //        admin.req({
            //            url: layui.setter.APIUrl + '/admin/departmentMgr/customerQuery', //实际使用请改成服务端真实接口
            //            type: 'post',
            //            data: { "groupId": val.id },
            //            done: function (res) {
            //                $('#DepartmentID_SelSource').empty();
            //                layui.each(res.Data, function (index, eachdata) {
            //                    $("#DepartmentID_SelSource").append("<option value='" + eachdata.PID + "'>" + eachdata.Name + "[" + eachdata.Code + "]</option>");
            //                });
            //                form.render('select');
            //            }
            //        });
            //    }


            //});
        });
    }


    layui.data.getSelSource = function (d, sourceName) {
        layui.use(['form', 'admin', 'tree'], function () {
            var $ = layui.$;
            var form = layui.form;
            var admin = layui.admin;
            var tree = layui.tree;



            //if (sourceName == "DepartmentID_SelSource") {
            //    admin.req({
            //        url: layui.setter.APIUrl + '/admin/departmentMgr/customerQuery', //实际使用请改成服务端真实接口
            //        type: 'post',
            //        data: { "groupId": d.GroupID },
            //        done: function (res) {
            //            $("#DepartmentID_SelSource").append("<option value=''>全部</option>");
            //            layui.each(res.Data, function (index, eachdata) {
            //                var strIsSel = '';
            //                if (eachdata.PID == d.DepartmentID_SelSource)
            //                    strIsSel = "selected='selected'";
            //                $("#DepartmentID_SelSource").append("<option value='" + eachdata.PID + "' " + strIsSel + ">" + eachdata.Name + "[" + eachdata.Code + "]</option>");
            //            });
            //            form.render('select');
            //        }
            //    });
            //}

        });
    }


    layui.data.setUpload = function (d) {
        layui.use(['upload', 'admin'], function () {
            var $ = layui.$,
                upload = layui.upload,
                admin = layui.admin;
            var formSelects = layui.formSelects;

            //上传头像
            var Photo_UploadSrc = $('#Photo_Upload');
            upload.render({
                url: '/WebAPI/file/uploadImg?access_token=' + layui.data('layuiAdmin').access_token
                , elem: '#Photo_UploadBtn'
                , accept: 'images'
                , method: 'get'
                , multiple: true
                , acceptMime: 'image/*'
                , done: function (res) {
                    if (res.ResultCode == 0) {
                        Photo_UploadSrc.val(res.Data.src);
                        layer.msg('上传成功');
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });

            //查看图片
            admin.events.Photo_UploadImg = function (othis) {
                var src = Photo_UploadSrc.val();
                layer.photos({
                    photos: {
                        "title": "查看头像", //相册标题
                        "data": [{
                            "src": src //原图地址
                        }]
                    }
                    , shade: 0.01
                    , closeBtn: 1
                    , anim: 5
                });
            };

        });
    }

    layui.data.datedone = function (d) {
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#LastLoginTime'
                , type: 'datetime'
                , calendar: true
            });
            laydate.val = d.LastLoginTime;

        });
    }

    layui.use(['form'], function () {
        var form = layui.form;//required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证） 自定义值
        var $ = layui.$;
        var admin = layui.admin;

    });

</script>